package Q3;

public class Solution {

    public static String solve (String s, String t) {
        // write code here

        int k = 0;
        for (; k < s.length(); k++) {
            if (s.charAt(k) != '0') {
                s = s.substring(k);
                break;
            }
        }
        if (k == s.length()) {
            return "0";
        }

        k = 0;
        for (; k < t.length(); k++) {
            if (t.charAt(k) != '0') {
                t = t.substring(k);
                break;
            }
        }
        if (k == t.length()) {
            return "0";
        }

        if ("0".equals(s) || "0".equals(t)) {
            return "0";
        }

        int len1 = s.length();
        int len2 = t.length();
        if (len1 < len2) {
            String temp = s;
            s = t;
            t = temp;
        }

        int[] arr1 = new int[len1];
        int[] arr2 = new int[len2];
        for (int i = 0; i < len1; i++) {
            arr1[i] = s.charAt(i) - 48;
        }
        for (int i = 0; i < len2; i++) {
            arr2[i] = t.charAt(i) - 48;
        }

        int n = len1;
        int m = len1 + len2 - 1;
        int[][] temp1 = new int[n][m];
        int count = 0;
        for (int i = len1 - 1; i >= 0; i--) {
            int index = m - 1 - count;
            for (int j = len2 - 1; j >= 0; j--) {
                temp1[i][index--] = arr1[i] * arr2[j];
            }
            count++;
        }

        int[] temp2 = new int[m + 1];
        for (int j = 1; j < m + 1; j++) {
            for (int i = 0; i < n; i++) {
                temp2[j] += temp1[i][j - 1];
            }
        }

        for (int j = m; j > 0; j--) {
            temp2[j - 1] += (temp2[j] / 10);
            temp2[j] %= 10;
        }

        int startIndex = (temp2[0] == 0 ? 1 : 0);
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = startIndex; i < m + 1; i++) {
            stringBuilder.append(temp2[i]);
        }

        return stringBuilder.toString();
    }

    public static void main(String[] args) {
        System.out.println(solve("1","2"));
    }
}
